// {}  网易深度优先 
const tree = {
    name: 'root',
    children: [
        {
            name: 'c1',
            children: [
                {
                    name: 'c11',
                    children: []
                },
                {
                    name: 'c12',
                    children: []
                }
            ]
        },
        {
            name: 'c2',
            children: [
                {
                    name: 'c21',
                    children: []
                },
                {
                    name: 'c22',
                    children: []
                }
            ]
        }
    ]
}

// 深度的方式遍历 [root, c1, c11, c12, c2, c21, c22]
function DFS(root) {
    // 
    let result = [],
        stack = [];

    if (!root) return [];

    stack.push(root);
    while(stack.length) {
        let node = stack.pop(); // 得到节点
        if (node == null) continue;  // 
        result.push(node.name);
        for (let i = node.children.length - 1; i >=0; i--) {
            stack.push(node.children[i])
        }
    }
    return result;
}

console.log(DFS(tree))